<?php /*a:2:{s:68:"H:\xampp\htdocs\www\lqb\application\login\view\login\Registered.html";i:1563842112;s:63:"H:\xampp\htdocs\www\lqb\application\login\view\public\head.html";i:1563842112;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台管理系统 - Layui</title>
    <script type="text/javascript" src="/static/admin/layui/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="/static/admin/layui/layui.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/admin/layui/css/layui.css" />
    <script type="text/javascript" src="/static/js/md5/md5.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">后台管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a id="updateAll" href="javascript:updateStatua()">更新贷款状态</a></li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    <span id="username" class="username"></span>
                </a>
                <!--<dl class="layui-nav-child">-->
                    <!--<dd><a href="">基本资料</a></dd>-->
                    <!--<dd><a href="">安全设置</a></dd>-->
                <!--</dl>-->
            </li>
            <li class="layui-nav-item"><a href="javascript:showTime()">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-shrink=""  lay-filter="test">

                <li class="layui-nav-item <?php if((app('request')->path() == 'login/Sign/addSign') OR (app('request')->path() == 'login/Sign/allSign')): ?>layui-nav-itemed<?php endif; ?>">
                    <a class="" href="javascript:;">渠道管理</a>
                    <dl class="layui-nav-child">
                        <dd class="<?php if(app('request')->path() == 'login/Sign/addSign'): ?>layui-this<?php endif; ?>"><a href="/login/Sign/addSign">添加渠道</a></dd>
                        <dd class="<?php if(app('request')->path() == 'login/Sign/allSign'): ?>layui-this<?php endif; ?>"><a href="/login/Sign/allSign">管理渠道</a></dd>
                        <!--<dd><a href="/admin/Category/index">推广等级</a></dd>-->
                        <!--<dd><a href="/admin/Grade/fetch_add_grade">添加等级</a></dd>-->
                    </dl>
                </li>

                <li class="layui-nav-item <?php if((app('request')->path() == 'login/Show/index') OR (app('request')->path() == 'login/Registered/index')): ?>layui-nav-itemed<?php endif; ?>">
                    <a class="" href="javascript:;">推广渠道</a>
                    <dl class="layui-nav-child">
                        <dd class="<?php if(app('request')->path() == 'login/Show/index'): ?>layui-this<?php endif; ?>"><a href="/login/Show/index">进来流量</a></dd>
                        <dd class="<?php if(app('request')->path() == 'login/Registered/index'): ?>layui-this<?php endif; ?>"><a href="/login/Registered/index">注册量</a></dd>
                    </dl>
                </li>

                <li class="layui-nav-item <?php if((app('request')->path() == 'login/Statistics/index')): ?>layui-nav-itemed<?php endif; ?>">
                    <a class="" href="javascript:;">统计</a>
                    <dl class="layui-nav-child">
                        <dd class="<?php if(app('request')->path() == 'login/Show/Statistics'): ?>layui-this<?php endif; ?>"><a href="/login/Statistics/index">流量统计</a></dd>
                    </dl>
                </li>

            </ul>
        </div>
    </div>

    <div id="main" class="layui-body">
        <!-- 内容主体区域 -->
       <blockquote class="layui-elem-quote" style="margin: 15px"><!-- 内容变量--></blockquote>
        

<form class="layui-form" style="margin: 20px">
    <div class="demoTable">
        条件搜索：

        <div class="layui-input-inline">
            <input name="time" type="text" class="layui-input" id="date" placeholder="时间范围" style="width: 100px">
        </div>

        <div class="layui-input-inline">
            <input name="phone" type="text" class="layui-input" id="phone" placeholder="手机号码" style="width: 100px">
        </div>

        <div class="layui-input-inline">
            <input name="ip" type="text" class="layui-input" id="ip" placeholder="IP" style="width: 100px">
        </div>

        <div class="layui-input-inline"  style="width: 100px">
            <select name="signData" id="signData" lay-filter="from_name">
                <option></option>
            </select>
        </div>

        <div class="layui-inline"  style="width: 100px">
            <select name="status" lay-verify="">
                <option value="">全部</option>
                <option value="1">未删除</option>
                <option value="-1">已删除</option>
            </select>
        </div>

        <div class="layui-inline"  style="width: 100px">
            <select name="first" lay-verify="">
                <option value="">注册</option>
                <option value="1">首次注册</option>
                <option value="-1">已被注册</option>
                <option value="2">重复注册</option>
            </select>
        </div>

        <div class="layui-inline"  style="width: 100px">
            <select name="type" lay-verify="">
                <option value="">贷款类型</option>
                <option value="d">单期</option>
                <option value="f">分期</option>
            </select>
        </div>

        <div class="layui-inline">
            <button class="layui-btn" lay-filter="submit" lay-submit>搜索</button>
            <button class="layui-btn layui-btn-primary"  lay-filter="submit" lay-submit>重置</button>
        </div>

    </div>
</form>

<table  class="layui-hide" id="all" lay-filter="all" lay-data="{id: 'sousuo'}"></table>

<script type="text/html" id="barDemo">
    {{#  if(d.status == 1){ }}<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> {{#  } }}
    {{#  if(d.status == -1){ }}<a class="layui-btn layui-btn-xs layui-btn-disabled">已删除</a> {{#  } }}
</script>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">删除选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
    </div>
</script>

<script type="text/html" id="getMoney">
    <a style="color: #04c7ff" lay-event="showMoney">{{d.phone}}</a>
</script>

<script type="text/html" id="getType">
    {{#  if(d.type == 'f'){ }} <a class="layui-btn layui-btn-xs layui-btn-normal">分期 </a> {{#  } }}
    {{#  if(d.type == 'd'){ }} <a class="layui-btn layui-btn-xs">单期 </a> {{#  } }}
</script>

<script type="text/html" id="getFirst">
    {{#  if(d.first == '1'){ }}  <a class="layui-btn layui-btn-xs layui-btn-normal">首次注册 </a>{{#  } }}
    {{#  if(d.first == '-1'){ }} <a class="layui-btn layui-btn-xs">已被注册 </a>{{#  } }}
    {{#  if(d.first == '2'){ }}  <a class="layui-btn layui-btn-xs layui-btn-danger">重复注册 </a>{{#  } }}
</script>


<script>
    layui.use(['table','layer','form','laydate'], function(){
        console.log('hello layui');
        var form = layui.form;
        var tokenValue = layui.data('cache');
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        table.render({
            elem: '#all'
            ,url:'/login/Show/getByFrom?model=Registered'
            ,toolbar: '#toolbarDemo'
            ,headers: {token: tokenValue.token}
            ,limit: 15
            ,limits: [10, 20, 40, 80, 160, 320, 640, 1280]
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'from', title:'推广方', width: 80}
                ,{field:'sign', title:'标识码', width: 80}
                ,{field:'logo', title:'商户标识', width: 80}
                ,{field:'phone', title:'注册手机',width: 123}
                ,{field:'first', title:'注册状态',toolbar: '#getFirst',width: 90}
                ,{field:'type', title:'贷款类型', toolbar: '#getType',width: 90}
                ,{field:'loan_status', title:'状态'}
                ,{field:'ip', title:'来源ip'}
                ,{field:'add_time', title:'添加时间'}
                ,{field:'record_id', title:'访问记录id'}
                ,{field:'url', title:'进来地址'}
                ,{field:'address', title:'来源地区'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150 , align: 'center'}
            ]]
            ,page: true
        });

        // 表格重载 用于搜索
        form.on('submit(submit)', function(data){
            var field=data.field;
            if($(data.elem).html()=="重置"){
                $("input").val("");
                field="";
                location.reload();
            }
            table.reload('all', {
                url: '/login/Show/byCondition?model=Registered',
                where: {field}
            });
            return false;
        });
        // 删除一行
        table.on('tool(all)', function(obj){
            var layer = layui.layer;
            var data = obj.data; //获得当前行数据
            var id = obj.data.id
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            // json = JSON.stringify(obj.data)
            var token = layui.data('cache') // 获取缓存中的token
            // console.log(json);
            if(obj.event == 'del'){
                layer.confirm('真的删除行么', function(index){
                    layer.close(index);
                    var arr = Array()
                    arr[0] = obj.data
                    var jsonData = JSON.stringify(arr);
                    //向服务端发送删除指令
                    $.post({
                        url:"/login/Del/delOnePopularize",
                        type:"post",
                        headers:{"token":token.token},
                        dataType:"json",
                        data:{'data':jsonData},
                        success:function (res) {
                            if(res.code == 400){
                                console.log(res.code)
                                console.log('success')
                                layer.msg('删除失败！！！请重试');
                            }
                            if(res.code == 200){
                                layer.msg('删除成功！！！');
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            }
                        },
                        error:function (error) {
                            if(error.responseJSON.error_code == 10001){
                                layer.msg('删除失败！！！权限不够');
                            }else {
                                layer.msg('服务器出错');
                            }
                        }
                    })
                });
            }
            if(obj.event == 'showMoney'){

                var index = layer.load(2, {time: 10*1000});
                var phone = obj.data.phone
                var type = obj.data.type
                var logo = obj.data.logo
                var token = layui.data('cache')
                $.get('/login/Registered/getPhoneInfo?phone='+ phone + '&type=' + type + '&logo=' + logo, {}, function(str){
                    layer.close(index);
                    layer.open({
                        type: 1,
                        title:'放款详情',
                        content: str.html //注意，如果str是object，那么需要字符拼接。
                    });
                    obj.update({
                        user_loan_money: str.data.money,
                        // user_loan_day: str.data.periods,
                        user_loan_get_money: str.data.get_money,
                        loan_status: str.data.status,
                    });
                });

            }
        });
        // 删除多行
        table.on('toolbar(all)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var token = layui.data('cache')
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.confirm('真的删除行么<br>'+JSON.stringify(data), function(index){
                        layer.close(index);
                        var jsonData = JSON.stringify(data);
                        //向服务端发送删除指令
                        $.post({
                            url:"/login/Del/delOnePopularize",
                            type:"post",
                            headers:{"token":token.token},
                            dataType:"json",
                            data:{'data':jsonData},
                            success:function (res) {
                                if(res.code == 400){
                                    console.log(res.code)
                                    console.log('success')
                                    layer.msg('删除失败！！！请重试');
                                }
                                if(res.code == 200){
                                    layer.msg('删除成功！！！');
                                    location.reload();  //删除对应行（tr）的DOM结构，并更新缓存
                                }
                            },
                            error:function (error) {
                                if(error.code == 500){
                                    layer.msg('删除失败！！！权限不够');
                                }
                            }
                        })
                    });
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
            };
        });

        laydate.render({
            elem: '#date' //指定元素
            ,range: '.'
        });

    });
</script>


    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 感谢
    </div>
</div>
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use(['element','form'], function(){
        var form = layui.form;
        // 获取本地缓存中的token
        var tokenValue = layui.data('cache');
        if(tokenValue.token !== 'undefined'){
            $.ajax({
                url:"/api/v1.Token/verifyToken",
                headers:{"token":tokenValue.token},
                type:"post",
                dataType:"json",
                success:function(res){
                    // 200则token不失效
                    if(res.code == 200){
                        var token = layui.data('cache')
                        $.ajax({
                            url:"/login/Show/getUserData",
                            type:"post",
                            headers:{"token":token.token},
                            dataType:"json",
                            success:function (res) {
                                $('#title').html(res.name + '推广详情页面')
                                $('#username').html(res.name)
                                data = res.sign
                                for(var key in data){
                                    $("#signData").append("<option value='" + data[key] + "'>" + data[key] + "</option>");
                                }
                                form.render('select');
                            }
                        })
                    }
                    // 404则token失效
                    if(res.code == 404 || res.code == 401){
                        window.location.href = "/login/Index/Timeout"
                    }
                },
                error:function(error){
                    console.log(error.responseJSON.code)
                    if(error.responseJSON.code == 401){
                        window.location.href = "/login/Index/Timeout"
                    }
                }
            })
        }

    });

    // 清除token退出
    function showTime(){
        layui.use(['element','form'], function(){
            var tokenValue = layui.data('cache');
            if(tokenValue.token){
                layui.data('cache', {
                    key: 'token'
                    ,remove: true
                });
            }
            // location.reload();
            window.location.href="/login/Index/out"
        })

    }
    function updateStatua() {
        var url = window.location.href;
        layui.use(['layer'], function(){
            var token = layui.data('cache').token;
            var layer = layui.layer;
            $.ajax({
                url:"/login/Registered/updateAllStatus",
                type:"post",
                headers:{"token":token},
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('更新成功,今天可用次数为'+ res.num + ',即将刷新页面');
                        setTimeout(function () {
                            window.location.href = url
                        }, 3000)
                    }
                    if(res.code == 400){
                        layer.msg('更新失败, 今天的可用次数为0');
                    }

                },
                error:function (error) {
                    layer.msg('更新成功');
                }
            })
        })
    }

    var tip_index = 0;
    $(document).on('mouseenter', '#updateAll', function(){
        tip_index = layer.tips('更新贷款状态，每天只能手动更新八次，后台每两个钟会自动更新一次，不会消耗手动更新次数', '#updateAll', {time: 0});
    }).on('mouseleave', '#updateAll', function(){
        layer.close(tip_index);
    });
</script>
</body>
</html>